package org.cjlm.muaction.frm;

import org.cjlm.ui.pub.MAbstraction;

import javax.swing.*;
import java.awt.event.ActionEvent;

public class FrameSortAction extends MAbstraction {
    public FrameSortAction(String title) {
        super(title);
    }
    @Override
    public void doAction(ActionEvent e) throws Exception {
        arrangeFrames();
    }

    public void arrangeFrames() {
        JInternalFrame[] frames = getDesktop().getAllFrames();
        int x = 0, y = 0;
        for (JInternalFrame frame : frames) {
            if (frame.isIcon())  continue;
            frame.setLocation(x,  y);
            x += 30;
            y += 30;
            if (y > 300) {
                y = 0;
                x += 300;
            }
        }
    }
}
